{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据清洗"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 0/1型字符数据转换为数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#导入数据+把0/1型字符数据转换为数值\n",
    "data_path='data.xlsx'\n",
    "data=pd.read_excel(io=data_path,encoding='gbk')\n",
    "def transform(row):\n",
    "    if row['是否续保']=='是':\n",
    "        row['是否续保']='1'\n",
    "    else:\n",
    "        row['是否续保']='0'\n",
    "    return row\n",
    "def transform2(row):\n",
    "    if row['客户类别']=='个人':\n",
    "        row['客户类别']='1'\n",
    "    else:\n",
    "        row['客户类别']='0'\n",
    "    return row\n",
    "def transform3(row):\n",
    "    if row['是否投保车损']=='投保车损':\n",
    "        row['是否投保车损']='1'\n",
    "    else:\n",
    "        row['是否投保车损']='0'\n",
    "    return row\n",
    "def transform4(row):\n",
    "    if row['是否投保盗抢']=='投保车损':\n",
    "        row['是否投保盗抢']='1'\n",
    "    else:\n",
    "        row['是否投保盗抢']='0'\n",
    "    return row\n",
    "def transform5(row):\n",
    "    if row['是否投保车上人员']=='投保车损':\n",
    "        row['是否投保车上人员']='1'\n",
    "    else:\n",
    "        row['是否投保车上人员']='0'\n",
    "    return row\n",
    "def transform6(row):\n",
    "    if row['保单性质']=='转保':\n",
    "        row['保单性质']='1'\n",
    "    else:\n",
    "        row['保单性质']='0'\n",
    "    return row\n",
    "def transform7(row):\n",
    "    if row['客户类别']=='个人':\n",
    "        row['客户类别']='1'\n",
    "    else:\n",
    "        row['客户类别']='0'\n",
    "    return row\n",
    "def transform8(row):\n",
    "    if row['险种']=='交强险':\n",
    "        row['险种']='1'\n",
    "    else:\n",
    "        row['险种']='0'\n",
    "    return row\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 删除无用项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#删除部分数据\n",
    "data=data.drop(['品牌'],axis=1)\n",
    "data=data.drop(['车系'],axis=1)\n",
    "data=data.drop(['起保日期'],axis=1)\n",
    "data=data.drop(['终止日期'],axis=1)\n",
    "data=data.drop(['保单号'],axis=1)\n",
    "data=data[~data['NCD'].isin(['新保无记录'])]\n",
    "data=data[~data['车辆用途'].isin(['重、中型载货汽车'])]\n",
    "data=data[~data['车辆用途'].isin(['其他汽车'])]\n",
    "data=data[~data['车辆种类'].isin(['特种二挂车'])]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "#生成训练用数据\n",
    "result=np.array(data['是否续保'].values)\n",
    "data=data.drop(['是否续保'],axis=1)\n",
    "predict=np.array(data.values)\n",
    "predict1=predict[:50000]\n",
    "predict2=predict[50000:-1]\n",
    "result1=result[:50000]\n",
    "result2=result[50000:-1]\n",
    "\n",
    "#训练logistics回归模型\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression(max_iter=100000,tol=1e-7)\n",
    "lr.fit(predict1,result1)\n",
    "\n",
    "\n",
    "#数据归一化\n",
    "def zero_one1(row):\n",
    "    row['三者险保额']=row['三者险保额']/2000000\n",
    "    return row\n",
    "def zero_one2(row):\n",
    "    row['签单保费']=row['签单保费']/38297\n",
    "    return row\n",
    "def zero_one3(row):\n",
    "    row['立案件数']=row['立案件数']/2000000\n",
    "    return row\n",
    "def zero_one4(row):\n",
    "    row['已决赔款']=row['已决赔款']/983620.00\n",
    "    return row\n",
    "def zero_one5(row):\n",
    "    row['新车购置价']=row['新车购置价']/5100000\n",
    "    return row\n",
    "def zero_one6(row):\n",
    "    row['车龄']=row['车龄']/24\n",
    "    return row\n",
    "def zero_one7(row):\n",
    "    row['被保险人年龄']=row['被保险人年龄']/75\n",
    "    return row\n",
    "def zero_one8(row):\n",
    "    row['续保年']=row['续保年']/8\n",
    "    return row\n",
    "\n",
    "data=data.apply(zero_one1,axis=1)\n",
    "data=data.apply(zero_one2,axis=1)\n",
    "data=data.apply(zero_one3,axis=1)\n",
    "data=data.apply(zero_one4,axis=1)\n",
    "data=data.apply(zero_one5,axis=1)\n",
    "data=data.apply(zero_one6,axis=1)\n",
    "data=data.apply(zero_one7,axis=1)\n",
    "data=data.apply(zero_one8,axis=1)\n",
    "\n",
    "\n",
    "#训练神经网络\n",
    "import sklearn.neural_network as sk_nn\n",
    "model = sk_nn.MLPClassifier(activation='relu',solver='adam',alpha=0.0001,learning_rate='adaptive',learning_rate_init=0.01,max_iter=2000)\n",
    "model.fit(predict1,result1)\n",
    "acc=model.score(predict2,result2) #根据给定数据与标签返回正确率的均值\n",
    "print('神经网络模型评价:',acc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 填充NA数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#将部分数据NAN填充\n",
    "data['被保险人性别']=data['被保险人性别'].fillna('N')\n",
    "data['已决赔款']=data['已决赔款'].fillna(0)\n",
    "data['三者险保额']=data['三者险保额'].fillna(0)\n",
    "data=data.fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 利用onehot把字符型数据转换为数字类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#利用onehot把值转换为数字类型\n",
    "data_dummies1=pd.get_dummies(data['车辆种类'])\n",
    "data_dummies2=pd.get_dummies(data['渠道'])\n",
    "data_dummies3=pd.get_dummies(data['投保类别'])\n",
    "data_dummies4=pd.get_dummies(data['车辆用途'])\n",
    "data_dummies5=pd.get_dummies(data['是否本省车牌'])\n",
    "data_dummies6=pd.get_dummies(data['NCD'])\n",
    "data_dummies7=pd.get_dummies(data['风险类别（A最低，E最高）'])\n",
    "data_dummies8=pd.get_dummies(data['使用性质'])\n",
    "data_dummies9=pd.get_dummies(data['被保险人性别'])\n",
    "\n",
    "data=data.drop(['车辆种类'],axis=1)\n",
    "data=data.drop(['渠道'],axis=1)\n",
    "data=data.drop(['投保类别'],axis=1)\n",
    "data=data.drop(['车辆用途'],axis=1)\n",
    "data=data.drop(['是否本省车牌'],axis=1)\n",
    "data=data.drop(['NCD'],axis=1)\n",
    "data=data.drop(['风险类别（A最低，E最高）'],axis=1)\n",
    "data=data.drop(['使用性质'],axis=1)\n",
    "data=data.drop(['客户类别'],axis=1)\n",
    "data=data.drop(['被保险人性别'],axis=1)\n",
    "\n",
    "data=pd.concat([data,data_dummies1],axis=1) \n",
    "data=pd.concat([data,data_dummies2],axis=1) \n",
    "data=pd.concat([data,data_dummies3],axis=1) \n",
    "data=pd.concat([data,data_dummies4],axis=1) \n",
    "data=pd.concat([data,data_dummies5],axis=1) \n",
    "data=pd.concat([data,data_dummies6],axis=1) \n",
    "data=pd.concat([data,data_dummies7],axis=1) \n",
    "data=pd.concat([data,data_dummies8],axis=1) \n",
    "data=pd.concat([data,data_dummies9],axis=1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'predict1' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-a045279fe125>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlinear_model\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mlr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmax_iter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m100000\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtol\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1e-7\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mlr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mresult1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'predict1' is not defined"
     ]
    }
   ],
   "source": [
    "#生成训练用数据\n",
    "result=np.array(data['是否续保'].values)\n",
    "data=data.drop(['是否续保'],axis=1)\n",
    "predict=np.array(data.values)\n",
    "predict1=predict[:50000]\n",
    "predict2=predict[50000:-1]\n",
    "result1=result[:50000]\n",
    "result2=result[50000:-1]\n",
    "\n",
    "#训练logistics回归模型\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "lr = LogisticRegression(max_iter=100000,tol=1e-7)\n",
    "lr.fit(predict1,result1)\n",
    "\n",
    "\n",
    "#数据归一化\n",
    "def zero_one1(row):\n",
    "    row['三者险保额']=row['三者险保额']/2000000\n",
    "    return row\n",
    "def zero_one2(row):\n",
    "    row['签单保费']=row['签单保费']/38297\n",
    "    return row\n",
    "def zero_one3(row):\n",
    "    row['立案件数']=row['立案件数']/2000000\n",
    "    return row\n",
    "def zero_one4(row):\n",
    "    row['已决赔款']=row['已决赔款']/983620.00\n",
    "    return row\n",
    "def zero_one5(row):\n",
    "    row['新车购置价']=row['新车购置价']/5100000\n",
    "    return row\n",
    "def zero_one6(row):\n",
    "    row['车龄']=row['车龄']/24\n",
    "    return row\n",
    "def zero_one7(row):\n",
    "    row['被保险人年龄']=row['被保险人年龄']/75\n",
    "    return row\n",
    "def zero_one8(row):\n",
    "    row['续保年']=row['续保年']/8\n",
    "    return row\n",
    "\n",
    "data=data.apply(zero_one1,axis=1)\n",
    "data=data.apply(zero_one2,axis=1)\n",
    "data=data.apply(zero_one3,axis=1)\n",
    "data=data.apply(zero_one4,axis=1)\n",
    "data=data.apply(zero_one5,axis=1)\n",
    "data=data.apply(zero_one6,axis=1)\n",
    "data=data.apply(zero_one7,axis=1)\n",
    "data=data.apply(zero_one8,axis=1)\n",
    "\n",
    "\n",
    "#训练神经网络\n",
    "import sklearn.neural_network as sk_nn\n",
    "model = sk_nn.MLPClassifier(activation='relu',solver='adam',alpha=0.0001,learning_rate='adaptive',learning_rate_init=0.01,max_iter=2000)\n",
    "model.fit(predict1,result1)\n",
    "acc=model.score(predict2,result2) #根据给定数据与标签返回正确率的均值\n",
    "print('神经网络模型评价:',acc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "result=np.array(data['是否续保'].values)\n",
    "data=data.drop(['是否续保'],axis=1)\n",
    "predict=np.array(data.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict1=predict[:50000]\n",
    "predict2=predict[50000:-1]\n",
    "result1=result[:50000]\n",
    "result2=result[50000:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.externals import joblib\n",
    "#joblib.dump(lr,\"logistic_lr.model\")  \n",
    "a=joblib.load(\"logistic_lr.model\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>5.上年发生2+有责事故</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   5.上年发生2+有责事故\n",
       "3             0\n",
       "4             0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[3:5,64:65]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "c=b[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.14539253e+01, -9.42519578e-01, -9.42519578e-01,\n",
       "        -4.41713772e-01, -4.41713772e-01, -4.32707589e-01,\n",
       "        -4.32707589e-01, -4.30917426e-01, -4.30917426e-01,\n",
       "        -4.02114658e-01, -4.02114658e-01, -2.63143897e-01,\n",
       "        -2.38901209e-01, -2.38901209e-01, -2.33167925e-01,\n",
       "        -2.33167925e-01, -1.93825452e-01, -1.93825452e-01,\n",
       "        -1.87115031e-01, -1.87115031e-01, -1.42009181e-01,\n",
       "        -1.42009181e-01, -1.39693889e-01, -1.39693889e-01,\n",
       "        -1.32837027e-01, -1.32837027e-01, -1.31300719e-01,\n",
       "        -1.31300719e-01, -1.29875987e-01, -1.29875987e-01,\n",
       "        -1.12760667e-01, -1.12760667e-01, -1.09967386e-01,\n",
       "        -1.09967386e-01, -1.06610979e-01, -1.06610979e-01,\n",
       "        -8.63607630e-02, -8.63607630e-02, -7.81197822e-02,\n",
       "        -7.70194576e-02, -4.68056327e-02, -4.68056327e-02,\n",
       "        -1.46069908e-02, -1.46069908e-02, -1.28099507e-02,\n",
       "        -1.28099507e-02, -6.24965099e-03, -6.24965099e-03,\n",
       "        -2.31300671e-03, -2.31300671e-03, -2.00459735e-03,\n",
       "        -2.00459735e-03, -1.41817800e-03, -1.41817800e-03,\n",
       "        -3.97377322e-04, -3.97377322e-04, -1.86049553e-04,\n",
       "        -1.86049553e-04, -1.84566435e-04, -1.84566435e-04,\n",
       "        -7.54733165e-07, -5.15496160e-07,  0.00000000e+00,\n",
       "         0.00000000e+00,  4.88285090e-06,  1.35524324e-04,\n",
       "         2.88728045e-03,  2.88728045e-03,  5.08612614e-03,\n",
       "         5.08612614e-03,  5.82603990e-03,  5.82603990e-03,\n",
       "         8.78123057e-03,  8.78123057e-03,  1.39570874e-02,\n",
       "         1.39570874e-02,  1.60056796e-02,  1.60056796e-02,\n",
       "         1.63606554e-02,  1.63606554e-02,  1.63899269e-02,\n",
       "         1.83464339e-02,  1.83464339e-02,  2.01603281e-02,\n",
       "         2.01603281e-02,  2.73834340e-02,  2.73834340e-02,\n",
       "         3.03482819e-02,  3.03482819e-02,  4.42245478e-02,\n",
       "         4.42245478e-02,  5.31194595e-02,  5.31194595e-02,\n",
       "         5.36102332e-02,  5.36102332e-02,  5.41829101e-02,\n",
       "         5.41829101e-02,  6.27424454e-02,  6.27424454e-02,\n",
       "         6.66913484e-02,  6.66913484e-02,  6.93569751e-02,\n",
       "         6.93569751e-02,  7.08177578e-02,  7.08177578e-02,\n",
       "         7.76724827e-02,  7.76724827e-02,  1.04721214e-01,\n",
       "         1.04721214e-01,  1.05040782e-01,  1.05040782e-01,\n",
       "         1.06317478e-01,  1.06317478e-01,  1.17995923e-01,\n",
       "         1.17995923e-01,  1.45966251e-01,  1.45966251e-01,\n",
       "         1.47206079e-01,  1.47206079e-01,  1.48057681e-01,\n",
       "         1.48057681e-01,  1.50238133e-01,  1.56221961e-01,\n",
       "         1.56221961e-01,  1.59678164e-01,  1.59678164e-01,\n",
       "         1.97699261e-01,  1.97699261e-01,  1.98129817e-01,\n",
       "         1.98129817e-01,  2.06392391e-01,  2.06392391e-01,\n",
       "         2.15643144e-01,  2.15643144e-01,  2.19468185e-01,\n",
       "         2.19468185e-01,  2.24903449e-01,  2.24903449e-01,\n",
       "         2.27989805e-01,  2.27989805e-01,  2.85661582e-01,\n",
       "         2.85661582e-01,  2.92890092e-01,  2.92890092e-01,\n",
       "         2.96017708e-01,  2.96017708e-01,  3.07719176e-01,\n",
       "         3.07719176e-01,  3.30214773e-01,  3.47920963e-01,\n",
       "         3.47920963e-01,  3.54957719e-01,  3.54957719e-01,\n",
       "         3.73094358e-01,  3.73094358e-01,  3.77144189e-01,\n",
       "         3.77144189e-01,  4.07109555e-01,  4.07109555e-01,\n",
       "         4.31197682e-01,  4.31197682e-01,  4.34318575e-01,\n",
       "         4.34318575e-01,  4.41024279e-01,  4.41024279e-01,\n",
       "         4.99561307e-01,  4.99561307e-01,  6.19647833e-01,\n",
       "         6.19647833e-01,  6.44356684e-01,  6.44356684e-01,\n",
       "         8.30717123e-01,  8.30717123e-01]])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def search(n,list):\n",
    "    i=0\n",
    "    for i in range(0,173):\n",
    "        if list[i]==n:\n",
    "            return i\n",
    "    return -1\n",
    "\n",
    "search(0.644356684,a.coef_[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'data' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-25-a854f1dace86>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m172\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'data' is not defined"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'predict1' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-399feccc7919>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msvm\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mSVC\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mclf\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mSVC\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprobability\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtol\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1e-3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mclf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mresult1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'predict1' is not defined"
     ]
    }
   ],
   "source": [
    "from sklearn.svm import SVC\n",
    "clf=SVC(probability=True,tol=1e-3)\n",
    "clf.fit(predict1,result1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv('temp.csv')\n",
    "data=pd.read_csv('temp.csv',index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#数据归一化\n",
    "def zero_one1(row):\n",
    "    row['三者险保额']=row['三者险保额']/2000000\n",
    "    return row\n",
    "def zero_one2(row):\n",
    "    row['签单保费']=row['签单保费']/38297\n",
    "    return row\n",
    "def zero_one3(row):\n",
    "    row['立案件数']=row['立案件数']/2000000\n",
    "    return row\n",
    "def zero_one4(row):\n",
    "    row['已决赔款']=row['已决赔款']/983620.00\n",
    "    return row\n",
    "def zero_one5(row):\n",
    "    row['新车购置价']=row['新车购置价']/5100000\n",
    "    return row\n",
    "def zero_one6(row):\n",
    "    row['车龄']=row['车龄']/24\n",
    "    return row\n",
    "def zero_one7(row):\n",
    "    row['被保险人年龄']=row['被保险人年龄']/75\n",
    "    return row\n",
    "def zero_one8(row):\n",
    "    row['续保年']=row['续保年']/8\n",
    "    return row\n",
    "\n",
    "data=data.apply(zero_one1,axis=1)\n",
    "data=data.apply(zero_one2,axis=1)\n",
    "data=data.apply(zero_one3,axis=1)\n",
    "data=data.apply(zero_one4,axis=1)\n",
    "data=data.apply(zero_one5,axis=1)\n",
    "data=data.apply(zero_one6,axis=1)\n",
    "data=data.apply(zero_one7,axis=1)\n",
    "data=data.apply(zero_one8,axis=1)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv('归一化第一版.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
